package storage.metadata;

import index.metadata.IndexInfo;
import index.metadata.IndexMgr;

import java.util.List;
import java.util.Map;

import storage.record.Schema;
import storage.record.TableInfo;
import storage.tx.Transaction;

public class MetadataMgr {
	private static TableMgr tblmgr;
	private static ViewMgr viewmgr;
	private static StatMgr statmgr;
	private static IndexMgr idxmgr;
	
	public MetadataMgr(boolean isnew, Transaction tx){
		tblmgr = new TableMgr(isnew, tx);
		viewmgr = new ViewMgr(isnew, tblmgr, tx);
		statmgr = new StatMgr(tblmgr, tx);
		idxmgr = new IndexMgr(isnew, tblmgr, tx);
	}
	
	public void createTable(String tblname, Schema sch, Transaction tx){
		System.out.println(tblname+" "+sch.fields().toString());
		tblmgr.createTable(tblname, sch, tx);
	}
	
	public TableInfo getTableInfo(String tblname, Transaction tx){
		return tblmgr.getTableInfo(tblname, tx);
	}
	
	public void createView(String viewname, String viewdef, Transaction tx){
		viewmgr.createView(viewname, viewdef, tx);
	}
	
	public String getViewDef(String viewname, Transaction tx){
		return viewmgr.getViewDef(viewname, tx);
	}
	
	public void createIndex(String tblname, String fldname, Transaction tx	){
		idxmgr.createIndex(tblname, fldname, tx);
	}
	
	public Map<String, IndexInfo> getIndexInfo(String tblname, Transaction tx){
		return idxmgr.getIndexInfo(tblname, tx);
	}
	
	public StatInfo getStatInfo(String tblname, TableInfo ti, Transaction tx){
		return statmgr.getStatInfo(tblname, ti, tx);
	}
	
	public void refreshSchema(String tblname, String fldname, String rtblname, String rfldname, Transaction tx){
		tblmgr.refreshSchema(tblname, fldname, rtblname, rfldname, tx);
	}
	
	public List<String> getTablenames(Transaction tx){
		return tblmgr.getTablenames(tx);
	}

}
